<?php

function p($value, $asString=false){
		if(DEBUG == true OR $_SESSION['user']['admin'] == 1){
			if($asString){
				if(gettype($value) == "array"){
					return "<pre>".print_r($value,1)."</pre>";
				}
				else{
					return "<pre>".$value."</pre>";
				}
			}
			else{
				if(gettype($value) == "array"){
					echo "<pre>".print_r($value,1)."</pre>";
				}
				else{
					echo "<pre>".$value."</pre>";
				}
			}
		}
}

function search($array, $key, $value)
{
	$results = array();

	if (is_array($array))
	{
		if (isset($array[$key]) && $array[$key] == $value)
			$results[] = $array;

		foreach ($array as $subarray)
			$results = array_merge($results, search($subarray, $key, $value));
	}

	return $results;
}

function secureStrings($s)	{
	$pattern = '/[0-9\?\.\+\/\\\*\(\)\[\]\{\}\^\'"!~,§\$%\&=;_#´`:\|<>°]+/isU';	// - Bindestrich zugelassen
	$replacement = '';
	return preg_replace($pattern, $replacement, $s);
}

function secureStringsNumbers($sn)	{
	// $pattern = '/[^a-zA-Z0-9\.\- ]+/';
	$pattern = '/[\?\.\-\+\/\\\*\(\)\[\]\{\}\^\'"!~,§\$%\&=;_#´`:\|<>°]+/isU';
	$replacement = '';
	return preg_replace($pattern, $replacement, $sn);
}

// interesting for BIG_INT
function secureNumber($number){	
	// nur Zahlen erlauben
	$wert = preg_replace('/[^0-9]/', '', $number);
	return $wert; 
}

// Sortiert ein 2 Dimensionales Array nach einem bestimmten Schl�ssel
// Bsp -> $processlist = orderArrayBy($processlist,'process_definition_responsible_name',SORT_DESC);
function orderArrayBy()	{
	$args = func_get_args();
	$data = array_shift($args);
	foreach ($args as $n => $field) {
		if (is_string($field)) {
			$tmp = array();
			foreach ($data as $key => $row) {
				$tmp[$key] = $row[$field];
			}
			$args[$n] = $tmp;
		}
	}
	$args[] = &$data;
	call_user_func_array('array_multisort', $args);
	return array_pop($args);
}

//  Nutzung des Ausgabepuffers um eine Datei "in einen String" einzubinden
function get_include_contents($filename) {
	if (is_file($filename)) {
		ob_start();
		include $filename;
		return ob_get_clean();
	}
	return false;
}

function recursive_array_search($needle,$haystack) {
	foreach($haystack as $key=>$value) {
		$current_key=$key;
		if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
			return $current_key;
		}
	}
	return false;
}

?>